Для начала создадим 2 файла:
1. File.php
2. Button.php
В первый запишем вот такой код:
<html> <head> <title>Counter</title> <meta http-equiv="Content-Type" content="text/html; charset=windows-utf-8" /> <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('#btn').click(function() { $.ajax({ url: "button.php", // полный путь - если вложенность в другие папки cache: false, type: 'Get', data:{book:1}, success: function(count) { $('#countinfo').html(count+" click"); } }); }); });/*end ready*/ </script> </head> <body > <input type="button" id="btn" value="Click here"/> <div id="countinfo"></div> </body> </html>
А во второй (button.php) вот такой код:
<?php if ($_GET['book']==1) { $file=fopen('dom.txt','a+'); flock($file,LOCK_EX); // выполнить эксплюзивное запирание $count=fread($file,100); $count++; ftruncate($file,0); fwrite($file,$count); flock($file,LOCK_UN);// отпираем файл fclose($file); echo $count; };?>